﻿Imports System.Net
Imports System.Net.Sockets

Public Module IPHelper
    Dim _localhostIP As Byte = 255

    Private Function LocalIP() As IPAddress
        For Each ip As IPAddress In From ip1 In Dns.GetHostEntry(Dns.GetHostName()).AddressList Where ip1.AddressFamily = AddressFamily.InterNetwork
            Return ip
        Next
        Return Nothing
    End Function

    Public ReadOnly Property LocalhostIP As Byte
        Get
            ' lazy
            If _localhostIP = 255 Then
                Dim s As String = LocalIP.ToString
                _localhostIP = Convert.ToByte(s.Substring(s.LastIndexOf(".") + 1))
            End If
            Return _localhostIP
        End Get
    End Property
End Module
